<template>
  <div class="count-box">
    <button class="sub" @click="handleSub" :disabled="value <= 1">-</button>
    <input class="inp" type="text" name="" id="" :value="value" @keydown.enter="handleChange($event)" @blur="handleChange($event)">
    <button class="add" @click="handleAdd">+</button>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: Number,
      default: 1
    }
  },
  methods: {
    handleSub () {
      this.$emit('subClick', this.value - 1)
    },
    handleAdd () {
      this.$emit('addClick', this.value + 1)
    },
    handleChange ($event) {
      this.$emit('input', $event.target.value)
      console.log($event.target.value)
    }
  }
}
</script>

<style lang="less" scoped>
.count-box {
  display: flex;
  justify-content: space-between;
  height: 30px;
  .add, .sub {
    width: 30px;
    outline: none;
    border: none;
    background-color: #efefef;
  }
  .inp {
    width: 40px;
    text-align: center;
    outline: none;
    border: none;
    background-color: #efefef;
    margin: 0px 3px;
  }
}
</style>
